package dome1;

public class Text {
    public static void main4(String[] args) {
        int[] arr = {1, 2, 3};
        try {
            System.out.println("before");
            //arr = null;
            System.out.println(arr[100]);
            System.out.println("after");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("after try catch");
    }
//    public static void main(String[] args) {
//        int[] arr = {1, 2, 3};
//        try {
//            System.out.println("before");
//            arr = null;
//            System.out.println(arr[100]);
//            System.out.println("after");
//        } catch (Exception e) { // Exception可以捕获到所有异常
//            e.printStackTrace();
//        } catch (NullPointerException e){ // 永远都捕获执行到
//            e.printStackTrace();
//        }
//        System.out.println("after try catch");
//    }
    public static void main2(String[] args) {
        try {
            int[] array = {1,2,3};
            System.out.println(array[3]); // 此处会抛出数组越界异常
        }catch (NullPointerException e){ // 捕获时候捕获的是空指针异常--真正的异常无法被捕获到
            e.printStackTrace();
        }
        System.out.println("后序代码");
    }
    public static void main1(String[] args) {
        int[] arr = {1, 2, 3};
        try {
            System.out.println("before");
            //arr = null;
            System.out.println(arr[100]);
            System.out.println("after");
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("这是个数组下标越界异常");
            e.printStackTrace();
        } catch (NullPointerException e) {
            System.out.println("这是个空指针异常");
            e.printStackTrace();
        }
        System.out.println("after try catch");
    }
}
